package org.huawei260.OD260;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.StringJoiner;

/**
 * @Auther: qingle
 * @Date: 2024/8/19-16:24
 * @Description: 小明今年升学到了小学一年级，
 * 来到新班级后，发现其他小朋友身高参差不齐，
 * 然后就想基于各小朋友和自己的身高差，对他们进行排序，
 * 请帮他实现排序
 *
 * @version: 1.0
 */
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringJoiner;
public class O0006_身高排序_ok {


//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int h = sc.nextInt();
			int n = sc.nextInt();

			Integer[] heights = new Integer[n];
			for (int i = 0; i < n; i++) heights[i] = sc.nextInt();

			System.out.println(getResult(h, heights));
		}

		public static String getResult(int h, Integer[] heights) {
			Arrays.sort(
				heights,
				(a, b) -> {
					int absA = Math.abs(a - h);
					int abaB = Math.abs(b - h);

					if (absA != abaB) return absA - abaB;
					else return a - b;
				});

			StringJoiner sj = new StringJoiner(" ");
			for (Integer height : heights) {
				sj.add(height + "");
			}
			return sj.toString();
		}
	}